const Verify = {
  /**
   * 验证手机号码
   * @param {Object} data
   */
  phone: data => {
    var number = data;

    if (typeof data === 'object') {
      number = data.phone === undefined ? '' : data.phone;
    }

    if (typeof number !== 'string' || number.length === 0) {
      return false;
    }

    return /^13[0-9]{1}[0-9]{8}$|14[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|16[0-9]{1}[0-9]{8}$|17[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$|19[0-9]{1}[0-9]{8}$/.test(number);
  },

  /**
   * 验证邮箱地址
   * @param {Object} data
   */
  email: data => {
    var number = data;
    if (typeof data === 'object') {
      number = data.email === undefined ? '' : data.email;
    }
    if (typeof number !== 'string' || number.length === 0) {
      return false;
    }
    return /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(number);
  },

  /**
   * 验证QQ
   * @param {Object} data
   */
  qq: data => {
    var number = data;
    if (typeof data === 'object') {
      number = data.qq === undefined ? '' : data.qq;
    }
    if (typeof number !== 'string' || number.length === 0) {
      return false;
    }

    return /^[1-9]\d{4,}$/.test(number);
  },
  /**
   * 身份证号码
   * @param {Object} data
   */
  idCard: data => {
    var number = data;

    if (typeof data === 'object') {
      number = data.id_card === undefined ? '' : data.id_card;
    }

    if (typeof number !== 'string' || number.length === 0) {
      return false;
    }

    return /^\d{6}(19|20)\d{2}([0][1-9]|11|12)([0,1,2][1-9]|[3][0,1])\d{3}([0-9]|X|x)$/.test(number);
  },
  // 验证是否是url地址
  url: (url: string) => {
    return /^[A-Za-z]+:\/\/[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&?/.=]+$/.test(url);
  },
  // 验证密码:字母+数字+特殊字符
  password: (password: string, strong: number = 1) => {
    if (strong === 1) {
      return /[\w]{6,18}$/.test(password);
    } else {
      return /^(?![a-zA-z]+$)(?!d+$)(?![!@#$%^&*]+$)(?![a-zA-zd]+$)(?![a-zA-z!@#$%^&*]+$)(?![d!@#$%^&*]+$)[a-zA-Zd!@#$%^&*]+$/.test(password);
    }
  }
};

export default Verify;
